'''
Created on May 2, 2012
TC ID: Ecom_5033
Desc: Kiem thu chuc nang tao mot su kien
@author: lavang
'''
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.calendarFunc import clickOnGoToCalendar, clickOnLinkAddEvent,\
    createEvent, isEventCreatedSuccessfully, showAllEvent

username=readData("username")
password=readData("password")
tm_event='this is event about summer 2012'

class Ecom_5033(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5033(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 2: Vao trang Calendar de tao su kien"
        clickOnGoToCalendar(self)
        
        print "Buoc 3: click 'Add Event' "
        clickOnLinkAddEvent(self)
        
        print "Buoc 4: Tao mot su kien"
        createEvent(self,day='10',month='Jun',year='2012',hour='19',min='20',event=tm_event,eventType='Global')
        
        print "Buoc 5: Xac nhan tao su kien thanh cong"
        showAllEvent(self)
        self.assertTrue(isEventCreatedSuccessfully(self,tm_event), "Failed!")
        print "Passed! Su kien duoc tao thanh cong"
        
    def tearDown(self):
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5033)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tao mot su kien'
                    )
    runner.run(suite)